<?php

use wopan\WoPan;

include_once __DIR__ . '/wopan/WoPan.php';
include_once __DIR__ . '/common.php';

use wopan\lib\WoPanAES;
// $api = new WoPan("1a97016e-36bd-4736-94f4-db1ec980b5da");
try {
    $api = WoPan::localLogin('155****1400', 'password');
    // sdump($api);
    // sdump($api->apiUser()->queryFamilyGroups());// 群组信息
    // sdump($api->wohome()->fCloudProductPackage());// 会员等级信息
    // sdump($api->wohome()->familyUserCurrent());// 我的信息
    // sdump($api->wohome()->queryAllFiles());// 查询文件列表
    // sdump($api->wohome()->queryTypeFiles(0,5));// 根据类别查询文件列表
    // sdump($api->wohome()->searchFile('1'));// 关键字搜索文件
    // sdump($api->wohome()->queryCloudUsageInfo('155****1400')); // 查询磁盘使用情况
    // sdump($api->wohome()->createDirectory('测试目录啊'));// 创建一个新的文件夹
    // sdump($api->wohome()->deleteFile(['046905317f2346b4b93c3f0b062376ea'])); // 删除目录、删除文件夹
    // sdump($api->wohome()->moveFile());// 移动目录、移动文件夹
    // sdump($api->wohome()->queryMuid());// 查询muid，解密错误
    // sdump($api->wohome()->queryRecycleData());// 查询回收站文件列表
    // sdump($api->wohome()->queryUploadLog());// 查询上传日志
    // sdump($api->wohome()->verifySetPwd());// 验证是否设置密码?
    // sdump($api->wohome()->shareFile(['a4f463d700914f9ca76025864ceaaabd']));// 分享文件
    // sdump($api->wohome()->cancelOrDelShareFile(['a4f463d700914f9ca76025864ceaaabd']));// 删除分享的文件
    // sdump($api->wohome()->renameFileOrDirectory('a4f463d700914f9ca76025864ceaaabd','1.exe'));// 重命名文件或目录
    // sdump($api->wohome()->getDownloadUrl(["D3cRimyfhi1GHWz3mlK6XpYRYTnEq/FNqGA7ZRZQDdSvmpmehZAxmLc29/b16S57"]));// 生成下载地址
    // sdump($api->wohome()->reductionRecycleData(["D3cRimyfhi1GHWz3mlK6XpYRYTnEq/FNqGA7ZRZQDdSvmpmehZAxmLc29/b16S57"]));// 还原回收站的文件
    echo "<hr>";
} catch (Exception $e) {
    sdump($e);
}

?>
<html>

<head>
    <title>沃云</title>
    <!-- 引入 CDN Crypto.js 开始 AES加密 注意引入顺序 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.0/core.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.0/enc-base64.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.0/md5.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.0/evpkdf.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.0/cipher-core.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.0/aes.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.0/mode-ecb.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.0/enc-utf8.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.0/enc-hex.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.0/pad-pkcs7.min.js"></script>
    <script src="/wopan/static/js/pad-zeropadding-min.js"></script>
    <!-- 引入 CDN Crypto.js 结束 -->
</head>

<body>
    <div>

    </div>
    <script type="text/javascript">
        let test_text = "<?php echo WoPanAES::encrypt("123", "10e66197-e6bd-436f-a040-530ab34e9b8b") ?>";
        let config = {
            baseURL: "https://iotpservice.smartont.net",
            timeout: 10000,
            key1: "应该是token",
            key2: "XFmi9GS2hzk98jGX" // 公共参数用到这个，然后加密key1
        }
        let security = {
            iv: "wNSOYIB1k1DjY5lA",
            // 加密
            encrypt(e, t) {
                t = this.getSuitableKey(t);
                var n = CryptoJS.enc.Utf8.parse(e),
                    r = CryptoJS.enc.Utf8.parse(t),
                    o = CryptoJS.enc.Utf8.parse(this.iv),
                    a = CryptoJS.AES.encrypt(n, r, {
                        iv: o,
                        mode: CryptoJS.mode.CBC,
                        padding: CryptoJS.pad.ZeroPadding
                    })
                return a.toString();
            },
            // 解密
            decrypt(e, t) {
                t = this.getSuitableKey(t);
                var n = CryptoJS.enc.Utf8.parse(t),
                    r = CryptoJS.enc.Utf8.parse(this.iv),
                    o = CryptoJS.AES.decrypt(e, n, {
                        iv: r,
                        mode: CryptoJS.mode.CBC,
                        padding: CryptoJS.pad.Pkcs7
                    });
                return o.toString(CryptoJS.enc.Utf8);
            },
            getSuitableKey(e) {
                return e.length > 16 ? e.slice(0, 16) : e;
            },
        }
    </script>
    <script>
        // 吐槽一下，分析半天就是一个md5加密
        let md5 = function(e) {
            var r = 0,
                i = 8;

            function o(e) {
                return g(a(A(e), e.length * i))
            }

            function a(e, t) {
                e[t >> 5] |= 128 << t % 32,
                    e[14 + (t + 64 >>> 9 << 4)] = t;
                for (var n = 1732584193, r = -271733879, i = -1732584194, o = 271733878, a = 0; a < e.length; a += 16) {
                    var c = n,
                        p = r,
                        A = i,
                        g = o;
                    n = u(n, r, i, o, e[a + 0], 7, -680876936),
                        o = u(o, n, r, i, e[a + 1], 12, -389564586),
                        i = u(i, o, n, r, e[a + 2], 17, 606105819),
                        r = u(r, i, o, n, e[a + 3], 22, -1044525330),
                        n = u(n, r, i, o, e[a + 4], 7, -176418897),
                        o = u(o, n, r, i, e[a + 5], 12, 1200080426),
                        i = u(i, o, n, r, e[a + 6], 17, -1473231341),
                        r = u(r, i, o, n, e[a + 7], 22, -45705983),
                        n = u(n, r, i, o, e[a + 8], 7, 1770035416),
                        o = u(o, n, r, i, e[a + 9], 12, -1958414417),
                        i = u(i, o, n, r, e[a + 10], 17, -42063),
                        r = u(r, i, o, n, e[a + 11], 22, -1990404162),
                        n = u(n, r, i, o, e[a + 12], 7, 1804603682),
                        o = u(o, n, r, i, e[a + 13], 12, -40341101),
                        i = u(i, o, n, r, e[a + 14], 17, -1502002290),
                        r = u(r, i, o, n, e[a + 15], 22, 1236535329),
                        n = s(n, r, i, o, e[a + 1], 5, -165796510),
                        o = s(o, n, r, i, e[a + 6], 9, -1069501632),
                        i = s(i, o, n, r, e[a + 11], 14, 643717713),
                        r = s(r, i, o, n, e[a + 0], 20, -373897302),
                        n = s(n, r, i, o, e[a + 5], 5, -701558691),
                        o = s(o, n, r, i, e[a + 10], 9, 38016083),
                        i = s(i, o, n, r, e[a + 15], 14, -660478335),
                        r = s(r, i, o, n, e[a + 4], 20, -405537848),
                        n = s(n, r, i, o, e[a + 9], 5, 568446438),
                        o = s(o, n, r, i, e[a + 14], 9, -1019803690),
                        i = s(i, o, n, r, e[a + 3], 14, -187363961),
                        r = s(r, i, o, n, e[a + 8], 20, 1163531501),
                        n = s(n, r, i, o, e[a + 13], 5, -1444681467),
                        o = s(o, n, r, i, e[a + 2], 9, -51403784),
                        i = s(i, o, n, r, e[a + 7], 14, 1735328473),
                        r = s(r, i, o, n, e[a + 12], 20, -1926607734),
                        n = l(n, r, i, o, e[a + 5], 4, -378558),
                        o = l(o, n, r, i, e[a + 8], 11, -2022574463),
                        i = l(i, o, n, r, e[a + 11], 16, 1839030562),
                        r = l(r, i, o, n, e[a + 14], 23, -35309556),
                        n = l(n, r, i, o, e[a + 1], 4, -1530992060),
                        o = l(o, n, r, i, e[a + 4], 11, 1272893353),
                        i = l(i, o, n, r, e[a + 7], 16, -155497632),
                        r = l(r, i, o, n, e[a + 10], 23, -1094730640),
                        n = l(n, r, i, o, e[a + 13], 4, 681279174),
                        o = l(o, n, r, i, e[a + 0], 11, -358537222),
                        i = l(i, o, n, r, e[a + 3], 16, -722521979),
                        r = l(r, i, o, n, e[a + 6], 23, 76029189),
                        n = l(n, r, i, o, e[a + 9], 4, -640364487),
                        o = l(o, n, r, i, e[a + 12], 11, -421815835),
                        i = l(i, o, n, r, e[a + 15], 16, 530742520),
                        r = l(r, i, o, n, e[a + 2], 23, -995338651),
                        n = f(n, r, i, o, e[a + 0], 6, -198630844),
                        o = f(o, n, r, i, e[a + 7], 10, 1126891415),
                        i = f(i, o, n, r, e[a + 14], 15, -1416354905),
                        r = f(r, i, o, n, e[a + 5], 21, -57434055),
                        n = f(n, r, i, o, e[a + 12], 6, 1700485571),
                        o = f(o, n, r, i, e[a + 3], 10, -1894986606),
                        i = f(i, o, n, r, e[a + 10], 15, -1051523),
                        r = f(r, i, o, n, e[a + 1], 21, -2054922799),
                        n = f(n, r, i, o, e[a + 8], 6, 1873313359),
                        o = f(o, n, r, i, e[a + 15], 10, -30611744),
                        i = f(i, o, n, r, e[a + 6], 15, -1560198380),
                        r = f(r, i, o, n, e[a + 13], 21, 1309151649),
                        n = f(n, r, i, o, e[a + 4], 6, -145523070),
                        o = f(o, n, r, i, e[a + 11], 10, -1120210379),
                        i = f(i, o, n, r, e[a + 2], 15, 718787259),
                        r = f(r, i, o, n, e[a + 9], 21, -343485551),
                        n = d(n, c),
                        r = d(r, p),
                        i = d(i, A),
                        o = d(o, g)
                }
                return Array(n, r, i, o)
            }

            function c(e, t, n, r, i, o) {
                return d(p(d(d(t, e), d(r, o)), i), n)
            }

            function u(e, t, n, r, i, o, a) {
                return c(t & n | ~t & r, e, t, i, o, a)
            }

            function s(e, t, n, r, i, o, a) {
                return c(t & r | n & ~r, e, t, i, o, a)
            }

            function l(e, t, n, r, i, o, a) {
                return c(t ^ n ^ r, e, t, i, o, a)
            }

            function f(e, t, n, r, i, o, a) {
                return c(n ^ (t | ~r), e, t, i, o, a)
            }

            function d(e, t) {
                var n = (65535 & e) + (65535 & t),
                    r = (e >> 16) + (t >> 16) + (n >> 16);
                return r << 16 | 65535 & n
            }

            function p(e, t) {
                return e << t | e >>> 32 - t
            }

            function A(e) {
                for (var t = Array(), n = (1 << i) - 1, r = 0; r < e.length * i; r += i)
                    t[r >> 5] |= (e.charCodeAt(r / i) & n) << r % 32;
                return t
            }

            function g(e) {
                for (var t = r ? "0123456789ABCDEF" : "0123456789abcdef", n = "", i = 0; i < 4 * e.length; i++)
                    n += t.charAt(e[i >> 2] >> i % 4 * 8 + 4 & 15) + t.charAt(e[i >> 2] >> i % 4 * 8 & 15);
                return n
            }

            return o(e);
        }
    </script>
</body>

</html>